//
//  MSLNormalSlider.m
//  GreetCard
//
//  Created by CPX on 2018/9/13.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "MSLNormalSlider.h"
/**
 贺卡滑动View
 */
@interface MSLNormalSlider ()
{
    NSString *_title,*_string_value;
    float _value_default, _value_max;
}
@end

@implementation MSLNormalSlider

-(instancetype)initWithTitle:(NSString *)title
                defaultValue:(float)value_default
                   value_max:(float)value_max
                 valueString:(NSString *)string_value{
    
    if (self  = [super init]){
        _title = title;
        _value_default = value_default;
        _string_value = string_value;
        _value_max = value_max;
        [self setupView];
    }
    return self;
}

-(void)setupView{
    self.titleLabel = [UILabel new];
    _titleLabel.font = [UIFont systemFontOfSize:15];
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.text = _title;
    
    _valueLabel = [UILabel new];
    _valueLabel.text = _string_value;

    _valueLabel.font = [UIFont systemFontOfSize:15];
    _valueLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    [self addSubview:_valueLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_top).offset(10);
        make.leading.equalTo(self.mas_leading).offset(0);
        
    }];
    [_valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.trailing.equalTo(self.mas_trailing).offset(0);
        
    }];
    _slider = [[UISlider alloc]init];
    _slider.minimumValue = 0;
    _slider.maximumValue = _value_max;
    _slider.value = _value_default;
    _slider.minimumTrackTintColor = [UIColor blackColor];
    _slider.maximumTrackTintColor = [UIColor lightGrayColor];
    [_slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
    
    [self addSubview:self.slider];
    [self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.leading.equalTo(self.titleLabel.mas_trailing).offset(10);
        make.centerX.equalTo(self);
    }];
    
    
}
-(void)sliderValueChange:(UISlider * )sender{

    if (self.sliderValueEvent){
        self.sliderValueEvent(sender.value,self);
    }
    
    

}
@end
